<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 需求一
      let arr = []
      let age = []
      for (let i = 0; i < 5; i++) {
        arr.push(+prompt(`请输入第${i + 1}个年龄`))
        if (age > 0 && age < 100) {
          arr.push(age)
        }
      }
      console.log(arr)

      // 需求二
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] >= 18) {
          document.write(` 所有成年人的年龄为 ${arr[i]} <br> `)
        }
      }
      // 需求三
      // let sum = 0
      // for (let i = 0; i < arr.length; i++) {
      //   sum += arr[i]
      // }
      // document.write(` 所有人总年龄是 ${sum} `)

      // 需求四
      let sum = 0
      for (let i = 0; i < arr.length; i++) {
        sum += arr[i]
      }
      document.write(` 所有人平均年龄是 ${sum / arr.length} `)
      // 需求五
      let max = arr[0]
      let min = arr[0]
      for (let i = 0; i < arr.length; i++) {
        // max = max < arr[i] ? arr[i] : max
        if (max < arr[i]) max = arr[i]
        if (min > arr[i]) min = arr[i]
      }
      console.log(max)
      console.log(min)
    </script>
  </body>
</html>
